﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Autodesk.Revit.DB;
using YArchitech.Controls;
using YArchitech.DataModel;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;

namespace YArchitech.HVAC
{
	public partial class FrmCommbinedPipline : System.Windows.Forms.Form
	{
		public FrmCommbinedPipline(Document doc)
		{
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
			this.doc = doc;
			//base.Icon = Resource.YArchitechIcon;
			this.userSetting = new HVACUserSetting();
			this.InitializeData();
			double num = 1.0;
			double num2 = 1.0;
			WinDPIManager.GetWinFormXYDpi(ref num, ref num2);
			base.Size = new Size(Convert.ToInt32(160.0 * num), Convert.ToInt32(170.0 * num2));
		}

		public FrmCommbinedPipline(Document doc, Element ele)
		{
			this.InitializeComponent();
			this.doc = doc;
			//base.Icon = Resource.YArchitechIcon;
			this.userSetting = new HVACUserSetting();
			this.SetSymbolName(ele);
			this.InitializeData();
		}

		private void btnSel_Click(object sender, EventArgs e)
		{
			this.IsPickup = true;
			base.Close();
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			if (this.rdoPipelineCategory.Checked && (string.IsNullOrEmpty(this.txtSymbolName.Text.Trim()) || this.ElemType == null))
			{
				YJKMessageBox.Show("您选择了“管线类别”合并方式，但未提取管线类别！");
				return;
			}
			base.DialogResult = DialogResult.OK;
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
		}

		private void rdoPipelineCategory_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rdoPipelineCategory.Checked)
			{
				this.btnSel.Enabled = true;
				this.txtSymbolName.Enabled = true;
				this.CombinedMethod = true;
			}
		}

		private void rdoSelByRectangle_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rdoSelByRectangle.Checked)
			{
				this.btnSel.Enabled = false;
				this.txtSymbolName.Enabled = false;
				this.CombinedMethod = false;
			}
		}

		private void FrmCommbinedPipline_FormClosed(object sender, FormClosedEventArgs e)
		{
			this.WriteData();
		}

		private void SetSymbolName(Element ele)
		{
			if (this.doc.GetElement(ele.GetTypeId()) != null)
			{
				this.ElemType = (this.doc.GetElement(ele.GetTypeId()) as ElementType);
				this.txtSymbolName.Text = this.ElemType.Name;
			}
		}

		private void InitializeData()
		{
			if (string.IsNullOrEmpty(this.userSetting.ReadValue("CommbinedPipline", "CommbinedType")) || this.userSetting.ReadValue("CommbinedPipline", "CommbinedType") == "0")
			{
				this.rdoPipelineCategory.Checked = true;
				return;
			}
			this.rdoSelByRectangle.Checked = true;
		}

		private void WriteData()
		{
			if (this.rdoPipelineCategory.Checked)
			{
				this.userSetting.WriteValue("CommbinedPipline", "CommbinedType", "0");
				return;
			}
			this.userSetting.WriteValue("CommbinedPipline", "CommbinedType", "1");
		}

		private Document doc;

		public bool IsPickup;

		private HVACUserSetting userSetting = new HVACUserSetting();

		public bool CombinedMethod = true;

		public ElementType ElemType;
	}
}
